package com.projectmanagement.model.data;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "Groups")
public class Group implements Serializable {

	private static final long serialVersionUID = 2722609148144412569L;

	@Id
	@Column(name = "id")
	@GeneratedValue
	private long id;

	@Column(name = "owner", nullable = false)
	private User owner;

	@Column(name = "name", nullable = false)
	private String name;

	@Column(name = "created_on", nullable = false)
	private Timestamp createdOn = new Timestamp(0);

	@Column(name = "description", nullable = true)
	private String description = "";

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "Group_files", joinColumns = { @JoinColumn(name = "file_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "group_id", referencedColumnName = "id") })
	private List<File> files;

	public Group() {
	}

	public Group(User user, String name) {
		this();
		this.name = name;
		this.owner = user;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Timestamp getCreatedOn() {
		return createdOn;
	}

	public void setCreatedOn(Timestamp createdOn) {
		this.createdOn = createdOn;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<File> getFiles() {
		return files;
	}

	public void setFiles(List<File> files) {
		this.files = files;
	}
}
